#!/bin/bash

logfile=pkg-ohpc
rm -f ${logfile}.*

echo ++++ search and log OpenHPC packages

if [ -e /etc/redhat-release ];then

    # query repo for ohpc packages
    repoquery -qa --queryformat='%{Name} %{Version} %{URL} %{Group} %{Summary}\n' | grep -e "-ohpc\b" >> ${logfile}.all

    info=`repoquery -q --queryformat='%{Name} %{Version} %{URL} %{Group} %{Summary}\n' ohpc-release`
    echo ${info} >>${logfile}.all

elif [ -e /etc/SuSE-release ];then
    for pkg in `zypper search -i *-ohpc` ; do
        name=`echo $pkg | grep -e -ohpc | cut -d '|' -f 2 | tr -d ' '`
        if [ "${name}" != "" ]; then
	    info=`rpm -q --queryformat='%{Name} %{Version} %{URL} %{Group} %{Summary}\n' $name`
	    echo ${info} >>${logfile}.all
        fi
    done

    info=`rpm -q --queryformat='%{Name} %{Version} %{URL} %{Group} %{Summary}\n' ohpc-release`
    echo ${info} >>${logfile}.all

else
    echo "ERROR: unknown distro type"
    exit 1
fi


echo
echo ++++ list of OpenHPC package groups
#groups=`grep -o 'ohpc/[^ ]*' pkg-ohpc.all | sort -u | cut -c5-`
groups=`grep -o 'ohpc/[^ ]*' pkg-ohpc.all | sort -u | cut -d '/' -f 2`

echo $groups
echo

for grp in ${groups}; do
    echo ++++ list of ohpc/${grp} packages installed
    grep "ohpc/${grp}" ${logfile}.all | sort -u 2>&1 | tee ${logfile}.${grp}
    echo 
done
